<template>
  <div class="topic">
    <div class="list">
      <div class="item"
       v-for="(item,index) in topicList" :key="index"
       @click="topicDetail(item.id)">
        <div class="img">
          <img :src="item.scene_pic_url" />
        </div>
        <div class="info">
          <p>{{item.title}}</p>
          <p>{{item.subtitle}}</p>
          <p>{{item.price_info}}元起</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { get } from '../../utils'
export default {
  data() {
    return {
      page: 1,
      topicList: [],
      total: ''
    }
  },
  // app.json中开启下拉刷新
  onPullDownRefresh() {
    this.page = 1
    this.getListData()
    wx.stopPullDownRefresh()
  },
  // 触底加载更多
  onReachBottom() {
    this.page = this.page + 1
    if(this.page > this.total) {
      return false
    } else {
      this.getListData()
    }
  },
  mounted() {
    this.getListData(true)
  },
  methods: {
    async getListData(first) {
      const data = await get('/topic/listAction', {
        page: this.page
      })
      // console.log(data)
      this.total = data.total
      // 与触底的数据进行拼接
      if (first) {
        this.topicList = data.data
      } else {
        this.topicList = this.topicList.concat(data.data)
      }
    },
    topicDetail(id) {
      wx.navigateTo({
        url: '/pages/topicdetail/main?id=' + id
      })
    }
  }
}
</script>

<style scoped>
@import './style.css';
</style>